package com.weds.custompage.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * @Description
 * @Author lihw
 * @Date 2023/9/1 14:30
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("msg")
    public String test( @RequestParam("name") String username){

        log.info("收到参数: {}", username);

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String name = request.getParameter("name");

        return name;


    }


    @PostMapping("msg2")
    public String test2( ){


        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String name = request.getParameter("name");
        Enumeration<String> parameterNames = request.getParameterNames();


        log.info("返回参数: {}", name);
        return name;


    }

}
